package main

import (
	"errors"
	"fmt"
	"io/ioutil"
)

func GetAllX(path string, files [] string, level int) ([]string, error) {
	//fmt.Println("Level", level)
	levelstr := ""
	if level == 1 {
		levelstr = "+"
	} else {
		for ; level > 1; level-- {
			levelstr += "\t|--"
		}
	}
	read, err := ioutil.ReadDir(path) //读取文件夹
	if err != nil {
		return files, errors.New("文件夹不可读取")
	}

	for _, fi := range read {
		if fi.IsDir() { //判读是否是文件夹
			fulldir := path + "\\" + fi.Name()          //构造新的路径
			files = append(files, levelstr+fulldir)     //追加路径

			files, _ = GetAllX(fulldir, files, level) //文件夹递归处理
			level++
		} else {
			fulldir := path + "\\" + fi.Name()      //构造新的路径
			files = append(files, levelstr+fulldir) //追加路径
		}
	}

	return files, nil
}

func main2() {
	path := "E:\\计算机技术\\Go\\腾讯课堂yincheng\\day1"
	files := []string{}
	files, _ = GetAllX(path, files, 1)
	for i := 0; i < len(files); i++ {
		fmt.Println(files[i])
	}
}

func main() {

}